<!DOCTYPE html>
<html lang=zh>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="基础程序设计标识符  凡是自己起名称的字符都叫标识符  比如类名、变量名、方法名、接口名、包名…   命名规则  1)、名称只能由字母、数字、下划线、$符号组成 2)、不能以数字开头 3)、名称不能使用JAVA中的关键字。 4)、坚决不允许出现中文及拼音命名。 5)、java中严格区分大小写，长度无限制   命名规范     包名：多单组成是所有字母都小写 packagename 类名接口名：多单">
<meta property="og:type" content="article">
<meta property="og:title" content="java基础结构">
<meta property="og:url" content="http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/index.html">
<meta property="og:site_name" content="chengsh">
<meta property="og:description" content="基础程序设计标识符  凡是自己起名称的字符都叫标识符  比如类名、变量名、方法名、接口名、包名…   命名规则  1)、名称只能由字母、数字、下划线、$符号组成 2)、不能以数字开头 3)、名称不能使用JAVA中的关键字。 4)、坚决不允许出现中文及拼音命名。 5)、java中严格区分大小写，长度无限制   命名规范     包名：多单组成是所有字母都小写 packagename 类名接口名：多单">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-07-24T20:28:47.413Z">
<meta property="article:modified_time" content="2020-07-24T20:28:47.413Z">
<meta property="article:author" content="chengsh">
<meta name="twitter:card" content="summary">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>java基础结构</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
      
<link rel="stylesheet" href="/css/rtl.css">

    
    <!-- rss -->
    
    
<meta name="generator" content="Hexo 4.2.1"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects_url">项目</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2020/07/24/hello-world/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/" target="_blank" rel="noopener"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&text=java基础结构" target="_blank" rel="noopener"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&is_video=false&description=java基础结构" target="_blank" rel="noopener"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=java基础结构&body=Check out this article: http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&name=java基础结构&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&t=java基础结构" target="_blank" rel="noopener"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#基础程序设计"><span class="toc-number">1.</span> <span class="toc-text">基础程序设计</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#标识符"><span class="toc-number">1.1.</span> <span class="toc-text">标识符</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#关键字"><span class="toc-number">1.1.1.</span> <span class="toc-text">关键字</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#class"><span class="toc-number">1.1.2.</span> <span class="toc-text">class</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#public"><span class="toc-number">1.1.3.</span> <span class="toc-text">public</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#变量"><span class="toc-number">1.2.</span> <span class="toc-text">变量</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#数据类型"><span class="toc-number">1.2.1.</span> <span class="toc-text">数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#基本数据类型"><span class="toc-number">1.2.1.1.</span> <span class="toc-text">基本数据类型</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#引用数据类型"><span class="toc-number">1.2.1.2.</span> <span class="toc-text">引用数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#String"><span class="toc-number">1.2.1.2.1.</span> <span class="toc-text">String</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#数据类型运算规则"><span class="toc-number">1.2.1.3.</span> <span class="toc-text">数据类型运算规则</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#自动类型提升"><span class="toc-number">1.2.1.3.1.</span> <span class="toc-text">自动类型提升</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#强制类型转换"><span class="toc-number">1.2.1.3.2.</span> <span class="toc-text">强制类型转换</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#生命周期"><span class="toc-number">1.2.1.4.</span> <span class="toc-text">生命周期</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#运算符"><span class="toc-number">1.3.</span> <span class="toc-text">运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#算术运算符"><span class="toc-number">1.3.1.</span> <span class="toc-text">算术运算符</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#流程控制"><span class="toc-number">1.4.</span> <span class="toc-text">流程控制</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#if-else-elseif"><span class="toc-number">1.4.1.</span> <span class="toc-text">if else  elseif</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#数组"><span class="toc-number">1.5.</span> <span class="toc-text">数组</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#算法"><span class="toc-number">1.5.1.</span> <span class="toc-text">算法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#数据结构"><span class="toc-number">1.5.2.</span> <span class="toc-text">数据结构</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#面向对象编程"><span class="toc-number">2.</span> <span class="toc-text">面向对象编程</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#类-对象"><span class="toc-number">2.1.</span> <span class="toc-text">类&#x2F;对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#类的结构"><span class="toc-number">2.2.</span> <span class="toc-text">类的结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#三大特性"><span class="toc-number">2.3.</span> <span class="toc-text">三大特性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#接口"><span class="toc-number">2.4.</span> <span class="toc-text">接口</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#设计模式"><span class="toc-number">2.5.</span> <span class="toc-text">设计模式</span></a></li></ol></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        java基础结构
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">chengsh</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2020-07-24T20:28:47.413Z" itemprop="datePublished">2020-07-24</time>
        
      
    </div>


      

      

    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h2 id="基础程序设计"><a href="#基础程序设计" class="headerlink" title="基础程序设计"></a>基础程序设计</h2><h3 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h3><blockquote>
<ul>
<li><p>凡是自己起名称的字符都叫标识符</p>
<blockquote>
<p>比如类名、变量名、方法名、接口名、包名…</p>
</blockquote>
</li>
<li><p>命名规则</p>
<blockquote>
<p>1)、名称只能由字母、数字、下划线、$符号组成</p>
<p>2)、不能以数字开头</p>
<p>3)、名称不能使用JAVA中的关键字。</p>
<p>4)、坚决不允许出现中文及拼音命名。</p>
<p>5)、java中严格区分大小写，长度无限制</p>
</blockquote>
</li>
<li><p>命名规范</p>
</li>
</ul>
<blockquote>
<ul>
<li>包名：多单组成是所有字母都小写 packagename</li>
<li>类名接口名：多单词组成时，所有单词的首字母大写 ClassName</li>
<li>变量名、方法名：多单词组成时，第一个单词首字母小写，第二个单词开始每个单词首字母大写：variableName </li>
<li>常量名：所有字母都大写。多单词时每个单词用下划线连接：FINAL_NAEM</li>
</ul>
</blockquote>
</blockquote>
<h4 id="关键字"><a href="#关键字" class="headerlink" title="关键字"></a>关键字</h4><blockquote>
<ul>
<li>被Java赋予了特殊含义的标识符、标识符：自定义名称的对象名称</li>
<li>关键字中所有字母都为小写</li>
<li>或非关键字 true、false</li>
<li>保留字：现有java版本未使用，以后可能会使用 goto、const</li>
</ul>
</blockquote>
<h4 id="class"><a href="#class" class="headerlink" title="class"></a>class</h4><blockquote>
<ul>
<li>一个文件可以有多个类</li>
<li>class关键只后面只能放类名</li>
</ul>
</blockquote>
<ul>
<li>代码示例 ：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">class1</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">class2</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="public"><a href="#public" class="headerlink" title="public"></a>public</h4><blockquote>
<p>一个类只能有一个public  且public 类名一定要与文件名一致</p>
</blockquote>
<ul>
<li>代码示例 ：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">class1</span></span>&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h3><ul>
<li>命名规则</li>
</ul>
<blockquote>
<ul>
<li>变量必须先声明，后使用</li>
<li>变量都定义在其作用域内。在作用域内，它是有效的。换句话说，出了作用域，就失效了</li>
<li>同一个作用域内，不可以声明两个同名的变量</li>
</ul>
</blockquote>
<ul>
<li><p>代码示例</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">VariableTest</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		<span class="comment">//变量的定义</span></span><br><span class="line">		<span class="keyword">int</span> myAge = <span class="number">12</span>;</span><br><span class="line">		<span class="comment">//变量的使用</span></span><br><span class="line">		System.out.println(myAge);</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//编译错误：使用myNumber之前并未定义过myNumber</span></span><br><span class="line">		<span class="comment">//System.out.println(myNumber);</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//变量的声明</span></span><br><span class="line">		<span class="keyword">int</span> myNumber;</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//编译错误：使用myNumber之前并未赋值过myNumber</span></span><br><span class="line">		<span class="comment">//System.out.println(myNumber);</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//变量的赋值</span></span><br><span class="line">		myNumber = <span class="number">1001</span>;</span><br><span class="line">		<span class="comment">//编译不通过</span></span><br><span class="line">		<span class="comment">//System.out.println(myClass);</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//不可以在同一个作用域内定义同名的变量</span></span><br><span class="line">		<span class="comment">//int myAge = 22;</span></span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">method</span><span class="params">()</span></span>&#123;</span><br><span class="line">		<span class="keyword">int</span> myClass = <span class="number">1</span>;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//class VariableTest &#123;&#125;//逆向思维，反证法</span></span><br></pre></td></tr></table></figure>
<h4 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h4></li>
</ul>
<h5 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h5><blockquote>
<ul>
<li>整型：byte \ short \ int \ long</li>
<li>浮点型：float \ double</li>
<li>字符型：char</li>
<li>布尔型：boolean    </li>
<li>基本数据类型的默认值</li>
</ul>
<blockquote>
</blockquote>
</blockquote>
<ul>
<li><p>代码演示</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">VariableTest1</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		<span class="comment">//1. 整型：byte(1字节=8bit) \ short(2字节) \ int(4字节) \ long(8字节)</span></span><br><span class="line">		<span class="comment">//① byte范围：-128 ~ 127</span></span><br><span class="line">		<span class="comment">//</span></span><br><span class="line">		<span class="keyword">byte</span> b1 = <span class="number">12</span>;</span><br><span class="line">		<span class="keyword">byte</span> b2 = -<span class="number">128</span>;</span><br><span class="line">		<span class="comment">//b2 = 128;//编译不通过</span></span><br><span class="line">		System.out.println(b1);</span><br><span class="line">		System.out.println(b2);</span><br><span class="line">		<span class="comment">// ② 声明long型变量，必须以"l"或"L"结尾</span></span><br><span class="line">		<span class="comment">// ③ 通常，定义整型变量时，使用int型。</span></span><br><span class="line">		<span class="keyword">short</span> s1 = <span class="number">128</span>;</span><br><span class="line">		<span class="keyword">int</span> i1 = <span class="number">1234</span>;</span><br><span class="line">		<span class="keyword">long</span> l1 = <span class="number">3414234324L</span>;</span><br><span class="line">		System.out.println(l1);</span><br><span class="line"></span><br><span class="line">		<span class="comment">//2. 浮点型：float(4字节) \ double(8字节)</span></span><br><span class="line">		<span class="comment">//① 浮点型，表示带小数点的数值</span></span><br><span class="line">		<span class="comment">//② float表示数值的范围比long还大</span></span><br><span class="line"></span><br><span class="line">		<span class="keyword">double</span> d1 = <span class="number">123.3</span>;</span><br><span class="line">		System.out.println(d1 + <span class="number">1</span>);</span><br><span class="line">		<span class="comment">//③ 定义float类型变量时，变量要以"f"或"F"结尾</span></span><br><span class="line">		<span class="keyword">float</span> f1 = <span class="number">12.3F</span>;</span><br><span class="line">		System.out.println(f1);</span><br><span class="line">		<span class="comment">//④ 通常，定义浮点型变量时，使用double型。</span></span><br><span class="line">		</span><br><span class="line">       </span><br><span class="line">		<span class="comment">//3. 字符型：char (1字符=2字节)</span></span><br><span class="line">		<span class="comment">//① 定义char型变量，通常使用一对'',内部只能写一个字符</span></span><br><span class="line">         <span class="comment">// char c =''; //编译不通过 有且只能放一个固定一个值不能为空</span></span><br><span class="line">         <span class="comment">// char c = 'a'+1; //c='b'; c+1= 98 ;(a=97)</span></span><br><span class="line">		<span class="keyword">char</span> c1 = <span class="string">'a'</span>;</span><br><span class="line">		<span class="comment">//编译不通过</span></span><br><span class="line">		<span class="comment">//c1 = 'AB';</span></span><br><span class="line">		System.out.println(c1);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">char</span> c2 = <span class="string">'1'</span>;</span><br><span class="line">		<span class="keyword">char</span> c3 = <span class="string">'中'</span>;</span><br><span class="line">		<span class="keyword">char</span> c4 = <span class="string">'ス'</span>;</span><br><span class="line">		System.out.println(c2);</span><br><span class="line">		System.out.println(c3);</span><br><span class="line">		System.out.println(c4);</span><br><span class="line"></span><br><span class="line">		<span class="comment">//② 表示方式：1.声明一个字符 2.转义字符 3.直接使用 Unicode 值来表示字符型常量</span></span><br><span class="line">		<span class="keyword">char</span> c5 = <span class="string">'\n'</span>;<span class="comment">//换行符</span></span><br><span class="line">		c5 = <span class="string">'\t'</span>;<span class="comment">//制表符</span></span><br><span class="line">		System.out.print(<span class="string">"hello"</span> + c5);</span><br><span class="line">		System.out.println(<span class="string">"world"</span>);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">char</span> c6 = <span class="string">'\u0043'</span>;</span><br><span class="line">		System.out.println(c6);</span><br><span class="line"></span><br><span class="line">		<span class="comment">//4.布尔型：boolean</span></span><br><span class="line">		<span class="comment">//① 只能取两个值之一：true 、 false</span></span><br><span class="line">		<span class="comment">//② 常常在条件判断、循环结构中使用</span></span><br><span class="line">		<span class="keyword">boolean</span> bb1 = <span class="keyword">true</span>;</span><br><span class="line">		System.out.println(bb1);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">boolean</span> isMarried = <span class="keyword">true</span>;</span><br><span class="line">		<span class="keyword">if</span>(isMarried)&#123;</span><br><span class="line">			System.out.println(<span class="string">"你就不能参加\"单身\"party了！\\n很遗憾"</span>);</span><br><span class="line">		&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">			System.out.println(<span class="string">"你可以多谈谈女朋友！"</span>);</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h5 id="引用数据类型"><a href="#引用数据类型" class="headerlink" title="引用数据类型"></a>引用数据类型</h5><blockquote>
<ul>
<li>类(class)</li>
<li>接口(interface)</li>
<li>数组(array)</li>
</ul>
<ol>
<li>引用类型在内存中的值默认是null</li>
</ol>
</blockquote>
<h6 id="String"><a href="#String" class="headerlink" title="String"></a><strong>String</strong></h6><blockquote>
<ol>
<li>String属于引用数据类型,翻译为：字符串</li>
<li>声明String类型变量时，使用一对””</li>
<li>String可以和8种基本数据类型变量做运算，且运算只能是连接运算：+</li>
<li>运算的结果仍然是String类型</li>
</ol>
</blockquote>
<ul>
<li>代码示例</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">StringTest</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		</span><br><span class="line">		String s1 = <span class="string">"Hello World!"</span>;</span><br><span class="line"></span><br><span class="line">		System.out.println(s1);</span><br><span class="line"></span><br><span class="line">		String s2 = <span class="string">"a"</span>;</span><br><span class="line">		String s3 = <span class="string">""</span>;</span><br><span class="line"></span><br><span class="line">		<span class="comment">//char c = '';//编译不通过</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//***********************</span></span><br><span class="line">		<span class="keyword">int</span> number = <span class="number">1001</span>;</span><br><span class="line">		String numberStr = <span class="string">"学号："</span>;</span><br><span class="line">		String info = numberStr + number;<span class="comment">// +：连接运算</span></span><br><span class="line">		<span class="keyword">boolean</span> b1 = <span class="keyword">true</span>;</span><br><span class="line">		String info1 = info + b1;<span class="comment">// +：连接运算</span></span><br><span class="line">		System.out.println(info1);</span><br><span class="line"></span><br><span class="line">		<span class="comment">//***********************</span></span><br><span class="line">		<span class="comment">//练习1</span></span><br><span class="line">		<span class="keyword">char</span> c = <span class="string">'a'</span>;<span class="comment">//97   A:65</span></span><br><span class="line">		<span class="keyword">int</span> num = <span class="number">10</span>;</span><br><span class="line">		String str = <span class="string">"hello"</span>;</span><br><span class="line">		System.out.println(c + num + str);<span class="comment">//107hello</span></span><br><span class="line">		System.out.println(c + str + num);<span class="comment">//ahello10</span></span><br><span class="line">		System.out.println(c + (num + str));<span class="comment">//a10hello</span></span><br><span class="line">		System.out.println((c + num) + str);<span class="comment">//107hello</span></span><br><span class="line">		System.out.println(str + num + c);<span class="comment">//hello10a</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//练习2</span></span><br><span class="line">		<span class="comment">//*	*</span></span><br><span class="line">		System.out.println(<span class="string">"*	*"</span>);</span><br><span class="line">		System.out.println(<span class="string">'*'</span> + <span class="string">'\t'</span> + <span class="string">'*'</span>);</span><br><span class="line">		System.out.println(<span class="string">'*'</span> + <span class="string">"\t"</span> + <span class="string">'*'</span>);</span><br><span class="line">		System.out.println(<span class="string">'*'</span> + <span class="string">'\t'</span> + <span class="string">"*"</span>);</span><br><span class="line">		System.out.println(<span class="string">'*'</span> + (<span class="string">'\t'</span> + <span class="string">"*"</span>));</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">		<span class="comment">//***********************</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//String str1 = 123;//编译不通过</span></span><br><span class="line">		String str1 = <span class="number">123</span> + <span class="string">""</span>;</span><br><span class="line">		System.out.println(str1);<span class="comment">//"123"</span></span><br><span class="line">		</span><br><span class="line">		<span class="comment">//int num1 = str1;</span></span><br><span class="line">		<span class="comment">//int num1 = (int)str1;//"123"</span></span><br><span class="line"></span><br><span class="line">		<span class="keyword">int</span> num1 = Integer.parseInt(str1);</span><br><span class="line">		System.out.println(num1);<span class="comment">//123</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>






<h5 id="数据类型运算规则"><a href="#数据类型运算规则" class="headerlink" title="数据类型运算规则"></a>数据类型运算规则</h5><h6 id="自动类型提升"><a href="#自动类型提升" class="headerlink" title="自动类型提升"></a>自动类型提升</h6><blockquote>
<p>结论：当容量小的数据类型的变量与容量大的数据类型的变量做运算时，结果自动提升为容量大的数据类型。<br>   byte 、char 、short –&gt; int –&gt; long –&gt; float –&gt; double </p>
<p>特别的：当byte、char、short三种类型的变量做运算时，结果为int型</p>
</blockquote>
<ul>
<li><p>代码示例</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">VariableTest2</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">byte</span> b1 = <span class="number">2</span>;</span><br><span class="line">		<span class="keyword">int</span> i1 = <span class="number">129</span>;</span><br><span class="line">		<span class="comment">//编译不通过</span></span><br><span class="line">		<span class="comment">//byte b2 = b1 + i1;</span></span><br><span class="line">		<span class="keyword">int</span> i2 = b1 + i1;</span><br><span class="line">		<span class="keyword">long</span> l1 = b1 + i1;</span><br><span class="line">		System.out.println(i2);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">float</span> f = b1 + i1;</span><br><span class="line">		System.out.println(f);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">short</span> s1 = <span class="number">123</span>;</span><br><span class="line">		<span class="keyword">double</span> d1 = s1;</span><br><span class="line">		System.out.println(d1);<span class="comment">//123.0</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//***************特别地*********************</span></span><br><span class="line">		<span class="keyword">char</span> c1 = <span class="string">'a'</span>;<span class="comment">//97</span></span><br><span class="line">		<span class="keyword">int</span> i3 = <span class="number">10</span>;</span><br><span class="line">		<span class="keyword">int</span> i4 = c1 + i3;</span><br><span class="line">		System.out.println(i4);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">short</span> s2 = <span class="number">10</span>;</span><br><span class="line">		<span class="comment">//char c2  = c1 + s2;//编译不通过</span></span><br><span class="line"></span><br><span class="line">		<span class="keyword">byte</span> b2 = <span class="number">10</span>;</span><br><span class="line">		<span class="comment">//char c3 = c1 + b2;//编译不通过</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//short s3 = b2 + s2;//编译不通过</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//short s4 = b1 + b2;//编译不通过</span></span><br><span class="line">		<span class="comment">//****************************************</span></span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h6 id="强制类型转换"><a href="#强制类型转换" class="headerlink" title="强制类型转换"></a>强制类型转换</h6><blockquote>
<p>自动类型提升运算的逆运算。</p>
<ol>
<li>需要使用强转符：()</li>
<li>注意点：强制类型转换，可能导致精度损失。</li>
<li>整型常量，默认类型为int型  int可以指给其他类型</li>
<li>浮点型常量，默认类型为double型  </li>
</ol>
</blockquote>
<ul>
<li><p>代码示例</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">VariableTest3</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">double</span> d1 = <span class="number">12.9</span>;</span><br><span class="line">		<span class="comment">//精度损失举例1</span></span><br><span class="line">		<span class="keyword">int</span> i1 = (<span class="keyword">int</span>)d1;<span class="comment">//截断操作</span></span><br><span class="line">		System.out.println(i1);</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//没有精度损失</span></span><br><span class="line">		<span class="keyword">long</span> l1 = <span class="number">123</span>;</span><br><span class="line">		<span class="keyword">short</span> s2 = (<span class="keyword">short</span>)l1;</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//精度损失举例2</span></span><br><span class="line">		<span class="keyword">int</span> i2 = <span class="number">128</span>;</span><br><span class="line">		<span class="keyword">byte</span> b = (<span class="keyword">byte</span>)i2;</span><br><span class="line">		System.out.println(b);<span class="comment">//-128</span></span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">VariableTest4</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//1.编码情况1：</span></span><br><span class="line">		<span class="keyword">long</span> l = <span class="number">123213</span>;</span><br><span class="line">		System.out.println(l);</span><br><span class="line">		<span class="comment">//编译失败：过大的整数</span></span><br><span class="line">		<span class="comment">//long l1 = 21332423235234123;</span></span><br><span class="line">		<span class="keyword">long</span> l1 = <span class="number">21332423235234123L</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">		<span class="comment">//****************</span></span><br><span class="line">		<span class="comment">//编译失败</span></span><br><span class="line">		<span class="comment">//float f1 = 12.3;</span></span><br><span class="line">		<span class="keyword">float</span> f1 = (<span class="keyword">float</span>)<span class="number">12.3</span>;</span><br><span class="line">		<span class="comment">//2.编码情况2：</span></span><br><span class="line">		<span class="comment">//整型常量，默认类型为int型</span></span><br><span class="line">		<span class="comment">//浮点型常量，默认类型为double型</span></span><br><span class="line">		<span class="keyword">byte</span> b = <span class="number">12</span>;</span><br><span class="line">		<span class="comment">//byte b1 = b + 1;//编译失败</span></span><br><span class="line"></span><br><span class="line">		<span class="comment">//float f1 = b + 12.3;//编译失败</span></span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


</li>
</ul>
<h5 id="生命周期"><a href="#生命周期" class="headerlink" title="生命周期"></a>生命周期</h5><blockquote>
<p>成员变量  vs  局部变量</p>
</blockquote>
<h3 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h3><h4 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</h4><ul>
<li>代码演示</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">运算符之一：算术运算符</span></span><br><span class="line"><span class="comment">+ - + - * / % (前)++ (后)++ (前)-- (后)-- +</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">AriTest</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//除号：/</span></span><br><span class="line">		<span class="keyword">int</span> num1 = <span class="number">12</span>;</span><br><span class="line">		<span class="keyword">int</span> num2 = <span class="number">5</span>;</span><br><span class="line">		<span class="keyword">int</span> result1 = num1 / num2;</span><br><span class="line">		System.out.println(result1);<span class="comment">//2</span></span><br><span class="line"></span><br><span class="line">		<span class="keyword">int</span> result2 = num1 / num2 * num2;</span><br><span class="line">		System.out.println(result2);<span class="comment">//10</span></span><br><span class="line"></span><br><span class="line">		<span class="keyword">double</span> result3 = num1 / num2;</span><br><span class="line">		System.out.println(result3);<span class="comment">//2.0</span></span><br><span class="line"></span><br><span class="line">		<span class="keyword">double</span> result4 = num1 / num2 + <span class="number">0.0</span>;<span class="comment">//2.0</span></span><br><span class="line">		<span class="keyword">double</span> result5 = num1 / (num2 + <span class="number">0.0</span>);<span class="comment">//2.4</span></span><br><span class="line">		<span class="keyword">double</span> result6 = (<span class="keyword">double</span>)num1 / num2;<span class="comment">//2.4</span></span><br><span class="line">		<span class="keyword">double</span> result7 = (<span class="keyword">double</span>)(num1 / num2);<span class="comment">//2.0</span></span><br><span class="line">		System.out.println(result5);</span><br><span class="line">		System.out.println(result6);</span><br><span class="line"></span><br><span class="line">		<span class="comment">// %:取余运算</span></span><br><span class="line">		<span class="comment">//结果的符号与被模数的符号相同</span></span><br><span class="line">		<span class="comment">//开发中，经常使用%来判断能否被除尽的情况。</span></span><br><span class="line">		<span class="keyword">int</span> m1 = <span class="number">12</span>;</span><br><span class="line">		<span class="keyword">int</span> n1 = <span class="number">5</span>;</span><br><span class="line">		System.out.println(<span class="string">"m1 % n1 = "</span> + m1 % n1);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">int</span> m2 = -<span class="number">12</span>;</span><br><span class="line">		<span class="keyword">int</span> n2 = <span class="number">5</span>;</span><br><span class="line">		System.out.println(<span class="string">"m2 % n2 = "</span> + m2 % n2);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">int</span> m3 = <span class="number">12</span>;</span><br><span class="line">		<span class="keyword">int</span> n3 = -<span class="number">5</span>;</span><br><span class="line">		System.out.println(<span class="string">"m3 % n3 = "</span> + m3 % n3);</span><br><span class="line"></span><br><span class="line">		<span class="keyword">int</span> m4 = -<span class="number">12</span>;</span><br><span class="line">		<span class="keyword">int</span> n4 = -<span class="number">5</span>;</span><br><span class="line">		System.out.println(<span class="string">"m4 % n4 = "</span> + m4 % n4);</span><br><span class="line">		</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//(前)++ :先自增1，后运算</span></span><br><span class="line">		<span class="comment">//(后)++ :先运算，后自增1</span></span><br><span class="line">		<span class="keyword">int</span> a1 = <span class="number">10</span>;</span><br><span class="line">		<span class="keyword">int</span> b1 = ++a1;</span><br><span class="line">		System.out.println(<span class="string">"a1 = "</span> + a1 + <span class="string">",b1 = "</span> + b1);</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">int</span> a2 = <span class="number">10</span>;</span><br><span class="line">		<span class="keyword">int</span> b2 = a2++;</span><br><span class="line">		System.out.println(<span class="string">"a2 = "</span> + a2 + <span class="string">",b2 = "</span> + b2);</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">int</span> a3 = <span class="number">10</span>;</span><br><span class="line">		++a3;<span class="comment">//a3++;</span></span><br><span class="line">		<span class="keyword">int</span> b3 = a3;</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//注意点：</span></span><br><span class="line">		<span class="keyword">short</span> s1 = <span class="number">10</span>;</span><br><span class="line">		<span class="comment">//s1 = s1 + 1;//编译失败</span></span><br><span class="line">		<span class="comment">//s1 = (short)(s1 + 1);//正确的</span></span><br><span class="line">		s1++;<span class="comment">//自增1不会改变本身变量的数据类型</span></span><br><span class="line">		System.out.println(s1);</span><br><span class="line"></span><br><span class="line">		<span class="comment">//问题：</span></span><br><span class="line">		<span class="keyword">byte</span> bb1 =<span class="number">127</span>;</span><br><span class="line">		bb1++;</span><br><span class="line">		System.out.println(<span class="string">"bb1 = "</span> + bb1);</span><br><span class="line"></span><br><span class="line">		<span class="comment">//(前)-- :先自减1，后运算</span></span><br><span class="line">		<span class="comment">//(后)-- :先运算，后自减1</span></span><br><span class="line">		</span><br><span class="line">		<span class="keyword">int</span> a4 = <span class="number">10</span>;</span><br><span class="line">		<span class="keyword">int</span> b4 = a4--;<span class="comment">//int b4 = --a4;</span></span><br><span class="line">		System.out.println(<span class="string">"a4 = "</span> + a4 + <span class="string">",b4 = "</span> + b4);</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>





<h3 id="流程控制"><a href="#流程控制" class="headerlink" title="流程控制"></a>流程控制</h3><h4 id="if-else-elseif"><a href="#if-else-elseif" class="headerlink" title="if else  elseif"></a>if else  elseif</h4><h3 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h3><h4 id="算法"><a href="#算法" class="headerlink" title="算法"></a>算法</h4><h4 id="数据结构"><a href="#数据结构" class="headerlink" title="数据结构"></a>数据结构</h4><h2 id="面向对象编程"><a href="#面向对象编程" class="headerlink" title="面向对象编程"></a>面向对象编程</h2><h3 id="类-对象"><a href="#类-对象" class="headerlink" title="类/对象"></a>类/对象</h3><h3 id="类的结构"><a href="#类的结构" class="headerlink" title="类的结构"></a>类的结构</h3><h3 id="三大特性"><a href="#三大特性" class="headerlink" title="三大特性"></a>三大特性</h3><h3 id="接口"><a href="#接口" class="headerlink" title="接口"></a>接口</h3><h3 id="设计模式"><a href="#设计模式" class="headerlink" title="设计模式"></a>设计模式</h3>
  </div>
  <div>
    <a href="https://github.com/clannadCheng/clannadCheng.github.io/edit/myblog/source/_posts/java基础结构.md" target="_blank">编辑</a>
  </div>
</article>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects_url">项目</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#基础程序设计"><span class="toc-number">1.</span> <span class="toc-text">基础程序设计</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#标识符"><span class="toc-number">1.1.</span> <span class="toc-text">标识符</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#关键字"><span class="toc-number">1.1.1.</span> <span class="toc-text">关键字</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#class"><span class="toc-number">1.1.2.</span> <span class="toc-text">class</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#public"><span class="toc-number">1.1.3.</span> <span class="toc-text">public</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#变量"><span class="toc-number">1.2.</span> <span class="toc-text">变量</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#数据类型"><span class="toc-number">1.2.1.</span> <span class="toc-text">数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#基本数据类型"><span class="toc-number">1.2.1.1.</span> <span class="toc-text">基本数据类型</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#引用数据类型"><span class="toc-number">1.2.1.2.</span> <span class="toc-text">引用数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#String"><span class="toc-number">1.2.1.2.1.</span> <span class="toc-text">String</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#数据类型运算规则"><span class="toc-number">1.2.1.3.</span> <span class="toc-text">数据类型运算规则</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#自动类型提升"><span class="toc-number">1.2.1.3.1.</span> <span class="toc-text">自动类型提升</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#强制类型转换"><span class="toc-number">1.2.1.3.2.</span> <span class="toc-text">强制类型转换</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#生命周期"><span class="toc-number">1.2.1.4.</span> <span class="toc-text">生命周期</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#运算符"><span class="toc-number">1.3.</span> <span class="toc-text">运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#算术运算符"><span class="toc-number">1.3.1.</span> <span class="toc-text">算术运算符</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#流程控制"><span class="toc-number">1.4.</span> <span class="toc-text">流程控制</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#if-else-elseif"><span class="toc-number">1.4.1.</span> <span class="toc-text">if else  elseif</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#数组"><span class="toc-number">1.5.</span> <span class="toc-text">数组</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#算法"><span class="toc-number">1.5.1.</span> <span class="toc-text">算法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#数据结构"><span class="toc-number">1.5.2.</span> <span class="toc-text">数据结构</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#面向对象编程"><span class="toc-number">2.</span> <span class="toc-text">面向对象编程</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#类-对象"><span class="toc-number">2.1.</span> <span class="toc-text">类&#x2F;对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#类的结构"><span class="toc-number">2.2.</span> <span class="toc-text">类的结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#三大特性"><span class="toc-number">2.3.</span> <span class="toc-text">三大特性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#接口"><span class="toc-number">2.4.</span> <span class="toc-text">接口</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#设计模式"><span class="toc-number">2.5.</span> <span class="toc-text">设计模式</span></a></li></ol></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/" target="_blank" rel="noopener"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&text=java基础结构" target="_blank" rel="noopener"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&is_video=false&description=java基础结构" target="_blank" rel="noopener"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=java基础结构&body=Check out this article: http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&title=java基础结构" target="_blank" rel="noopener"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&name=java基础结构&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2020/07/24/java%E5%9F%BA%E7%A1%80%E7%BB%93%E6%9E%84/&t=java基础结构" target="_blank" rel="noopener"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
    
    
    2016-2020
    chengsh
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects_url">项目</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->

<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">


<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">


    <!-- jquery -->

<script src="/lib/jquery/jquery.min.js"></script>


<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>

<!-- clipboard -->

  
<script src="/lib/clipboard/clipboard.min.js"></script>

  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"复制到粘贴板!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "复制成功!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

<!-- Disqus Comments -->


</body>
</html>
